<?php

class HTML_FormElements_Button extends FormElements implements HTMLElements {
	/**
	 * Button specific attributes
	 */
	private $attributeDisabled;
	
	
	/**
	 * Finals used for attributes of button
	 */
	const HTML_BUTTON = 'button';
	const TYPE_SUBMIT = 'submit';
	const TYPE_RESET = 'reset';
	const TYPE_BUTTON = 'button';
	const DISABLED_DISABLED = 'disabled=""';
	const DISABLED_ENABLED = '';
	const ATTRIBUTE_DISABLED = 'disabled';
	
	
/**
	 * 
	 * This function creates a complete Link-Element.
	 * The attributes have to be passed within an array. Possible attributes are:
	 * 	- $class
	 * 	- $id
	 * 	- $title
	 *  - $name
	 *  - $type
	 *  - $value
	 *  - $disabled
	 *  - $onclick
	 * @param unknown_type $parent
	 * @param String[][] $properties
	 */
	public function __construct($parent, $properties)  {
		PropertySetter::setProperties($this, $properties);
		$parent->addChildElement($this);
	}
	
	public function setAttributeDisabled ($disabled)  {
		$this->attributeDisabled = $disabled;
	}
	
	public function getAttributeDisabled ()  {
		return $this->attributeDisabled;
	}
	
	public function getButtonAttributes ()  {
		
		$output = '';
		
		if (!empty($this->attributeDisabled))  {
			$output .= $this->getAttributeDisabled();
		}
		
		if ($output == '')  {
			$output = ' ';
		}
		
		return $output;
	}
	
	public static function getAttributes ()  {
		$attributes = array();
		$parentAttributes = parent::getAttributes();
		$attributes[] = self::ATTRIBUTE_DISABLED;
		return array_merge($parentAttributes, $attributes);
	}
	
	/**
	 * This function is used to return the complete button with all attributes
	 */
	public function toString ()  {
		$output =	'<'. self::HTML_BUTTON.
					$this->getHTMLAttributes().
					$this->getFormElementsAttributes().
					$this->getButtonAttributes(). '>';
		
		if ($this->getChildElements())  {
			foreach ($this->getChildElements() as $element)  {
				$output .= $element->toString();
			}
		}
		
		$output .= '</'. self::HTML_BUTTON. '>';
		
		return $output;
	}
	
	
}
?>